/**
 * Copyright 2008-2009 HAN.BIFANG
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package han.bifang.gwt.client.service.content;

import han.bifang.gwt.client.common.Content;
import han.bifang.gwt.client.common.RequestObject;
import han.bifang.gwt.client.common.ResponseObject;
import han.bifang.gwt.client.communicate.BifangGWTServiceAsync;
import han.bifang.gwt.client.service.ServiceContentConstants;
import han.bifang.gwt.client.service.ServiceMessages;

import java.util.HashMap;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * 
 * @Author Kent
 */
public class RemoveVersionContent extends Content {
	private BifangGWTServiceAsync service = null;

	private VerticalPanel panel = null;

	private ServiceMessages cons;
	
	private String id;
	
	private AsyncCallback<ResponseObject> cb = new AsyncCallback<ResponseObject>() {
		public void onSuccess(ResponseObject res) {
			String code = res.getCode();
			if (!code.equals("0")) {
				Window.alert("There was an error: " + res.getMsg());
				return;
			}
//			HashMap h = new HashMap();
//			h.put("id", id);
			listener.onContentChanged(
					ServiceContentConstants.REMOVE_VERSION,
					ServiceContentConstants.SERVICE_ROOT, null);

		}

		public void onFailure(Throwable caught) {
			Window.alert("There was an error: " + caught.toString());
		}

	};
	
	

	public RemoveVersionContent(ServiceMessages cons, BifangGWTServiceAsync services,
			String vid,String version) {
		this.cons = cons;
		this.service = services;
		this.id = vid;
		
		VerticalPanel panel = new VerticalPanel();
		panel.setSpacing(5);
		panel.setWidth("100%");
		
		panel.add(new HTML(cons.confirmVersionRemove(version)));
		
		HorizontalPanel h1 = new HorizontalPanel();
		Button c = new Button(cons.confirm());
		c.addClickListener(new ClickListener() {

			public void onClick(Widget sender) {
				RequestObject req = new RequestObject();
				req.setRequest(id);
				req.setAction("han.bifang.gwt.server.action.service.RemoveVersionAction");
				service.call(req, cb);

			}

		});
		h1.add(c);
		h1.add(new HTML("&nbsp;&nbsp;&nbsp;"));
		
		Button b = new Button(cons.cancel());
		b.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				HashMap h = new HashMap();
				h.put("id", id);
				listener.onContentChanged(
						ServiceContentConstants.REMOVE_VERSION,
						ServiceContentConstants.VERSION_ROOT, h);

			}
		});
		h1.add(b);
		panel.add(h1);
		
		
		

		initWidget(panel);

	}

	
	
	
	
	
	

}
